package com.cml.dm.admin.service;

import com.cml.dm.admin.entity.DmExeLogger;
import com.cml.dm.admin.entity.DmMetadata;
import com.cml.dm.admin.service.sql.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SqlGenerateServiceFactory {
    @Autowired
    private DefaultBackupSqlGenerateService defaultBackupSqlGenerateServiceFactory;

    @Autowired
    private JoinNodeBackupSqlGenerateService joinNodeBackupSqlGenerateService;

    @Autowired
    private DefaultDeleteRecoverySqlGenerateService defaultDeleteRecoverySqlGenerateService;

    @Autowired
    private DefaultRecoverySqlGenerateService defaultRecoverySqlGenerateService;

    @Autowired
    private JoinNodeDeleteRecoverySqlGenerateService joinNodeDeleteRecoverySqlGenerateService;
    private RecoverySqlGenerateService recoverySqlGenerateService;

    public SqlGenerateService getSqlGenerateService(DmMetadata dmMetadata, DmExeLogger dmExeLogger, Object extParameter){
        //备份
        if(dmExeLogger.getExeType().equals(dmExeLogger.backup())){
            if(StringUtils.isEmpty(dmMetadata.getJoinUpPkNode())){
                return defaultBackupSqlGenerateServiceFactory;
            }
            return  joinNodeBackupSqlGenerateService;
        }else if(dmExeLogger.getExeType().equals(dmExeLogger.recovery())){//返回恢复
            return defaultRecoverySqlGenerateService;
        }
        //删除
        if(StringUtils.isEmpty(dmMetadata.getJoinUpPkNode())){
            return defaultDeleteRecoverySqlGenerateService;
        }
        return  joinNodeDeleteRecoverySqlGenerateService;
    }
}

